<%--
  Created by IntelliJ IDEA.
  User: sofwin
  Date: 2021/9/28
  Time: 11:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%String path = request.getContextPath()+"/";%>
<!doctype html>
<html>
<head>
    <base href="<%=path%>">
    <title>树状资源信息</title>
    <link href="hplus-master/css/bootstrap.min.css?v=3.3.7" rel="stylesheet" />
    <link href="hplus-master/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" />
    <link href="hplus-master/css/animate.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css">
    <link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css"/>

</head>
<body>

<div id="tree" class="ztree"></div>

<button type="button" id="save">保存</button>
<!-- 全局js -->
<script src="hplus-master/js/jquery.min.js?v=2.1.4"></script>
<script src="hplus-master/js/plugins/layer/layer.min.js"></script>
<script src="hplus-master/js/bootstrap.min.js?v=3.3.7"></script>
<script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>

<script src="js/jquery.ztree.core.js"></script>
<script src="js/jquery.ztree.excheck.js"></script>
<script src="js/qs.js"></script>
</body>
<script>
    let treeObject;
    let setting={
        check:{
            enable: true
        },
        callback:{
            onCheck:function (event,treeId,treeNode) {
            }
        },
        data:{
            simpleData:{
                enable:true,
                idKey:'resourceId',
                pIdKey:'parentId'
            },
            key:{
                name: 'resourceName'
            }
        }
    };
    let treeNodes;
    $(function(){
        $.modal.post('resource/data',{roleId:'${role.roleId}'},function (ret) {
            treeNodes = ret.data;
            treeObject =$.fn.zTree.init($("#tree"),setting,treeNodes);
            treeObject.expandAll(true);
        });
        $("#save").click(function () {
            let array = treeObject.getCheckedNodes(true);
            let ids = new Array();
            for(let i=0;i<array.length;i++){
                ids.push(array[i].resourceId)
            }
            let roleId='${role.roleId}';
            $.modal.post('role/savePermission',{roleId:roleId,ids:ids},function (ret) {
                if(ret.code==200){
                    layer.msg(ret.msg,function () {
                        parent.close(false);
                    })
                }else{
                    layer.msg(ret.msg);
                }
            })
        });
    })
</script>
</html>
